<?php

/**
 * api actions.
 *
 * @package    jobeet
 * @subpackage api
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class apiActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
	
	public function executeList(sfWebRequest $request)
	  {
	    $this->jobs = array();
	    foreach ($this->getRoute()->getObjects() as $job)
	    {
	      $this->jobs[$this->generateUrl('job_show_user', $job, true)] = $job->asArray($request->getHost());
	    }
	 
	    switch ($request->getRequestFormat())
	    {
	      case 'yaml':
	        $this->setLayout(false);
	        $this->getResponse()->setContentType('text/yaml');
	        break;
	    }
	  }
		  
	public function executeSearch(sfWebRequest $request)
	{
	  $this->forwardUnless($query = $request->getParameter('query'), 'job', 'index');
	 
	  echo '<br/>QUERY : ' . $query;
	  $this->jobs = Doctrine_Core::getTable('JobeetJob')->getForLuceneQuery($query);
	 
	  if ($request->isXmlHttpRequest())
	  {
		  if ('*' == $query || !$this->jobs)
	    {
	      return $this->renderText('No results.');
	    }
	    return $this->renderPartial('job/list', array('jobs' => $this->jobs));
	  }
	}
}
